home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today (Latin America) Volume 1 #6 / CD-ROM Today 6 Latam.iso / referenc / evol / database.dxr / 00143_ScanTag Handlers.ls < prev    next >
Encoding:
Text File  |  1996-11-08  |  3.3 KB  |  126 lines

  1. on initScanTag
  2.   global gGlossNum, gGlossNumLines
  3.   set glossNum to the number of member "glossary"
  4.   set lc to the number of lines in field glossNum
  5.   set gGlossNum to glossNum
  6.   set gGlossNumLines to lc
  7. end
  8.  
  9. on resetScanTag
  10.   global gScanCount
  11.   set gScanCount to -1
  12. end
  13.  
  14. on scanTag
  15.   global gScanCount, wc, gStartT, gSecondGlossWord
  16.   set fMem to 17
  17.   set TagColour to 137
  18.   if voidp(gScanCount) or (gScanCount < 0) then
  19.     set gScanCount to 1
  20.     set wc to the number of words in field fMem
  21.     resetHit()
  22.     set gStartT to the timer
  23.   end if
  24.   if gScanCount < wc then
  25.     set aword to word gScanCount of field fMem
  26.     set matchCount to matchWord(aword)
  27.     if matchCount = 1 then
  28.       set the foreColor of word gScanCount of field fMem to TagColour
  29.     else
  30.       if (matchCount = 2) and (gScanCount < wc) then
  31.         if gSecondGlossWord = word gScanCount + 1 of field fMem then
  32.           set the foreColor of word gScanCount to gScanCount + 1 of field fMem to TagColour
  33.         end if
  34.       end if
  35.     end if
  36.     set gScanCount to gScanCount + 1
  37.     if gScanCount = wc then
  38.       set EndT to the timer
  39.       set duration to EndT - gStartT
  40.       put "elapsed = " & duration & "   Rate = " & wc * 60.0 / duration & " wps"
  41.     end if
  42.   end if
  43. end
  44.  
  45. on matchWord oWord
  46.   global gGlossNum, gGlossNumLines, gHitList, gSecondGlossWord
  47.   if the number of chars in oWord < 3 then
  48.     return 0
  49.   end if
  50.   set aword to wordFilter(oWord)
  51.   if voidp(gGlossNum) or voidp(gGlossNumLines) then
  52.     makegloss()
  53.   end if
  54.   set glossNum to gGlossNum
  55.   set stPt to 1
  56.   set EndPt to gGlossNumLines
  57.   set bExit to 0
  58.   set bFound to 0
  59.   set gSecondGlossWord to EMPTY
  60.   repeat while not bExit
  61.     set midPt to (stPt + EndPt) / 2
  62.     set midLine to line midPt of field glossNum
  63.     set midLineWord1 to word 1 of midLine
  64.     set midLineWord1s to midLineWord1 & "s"
  65.     if (midLineWord1 = aword) or (midLineWord1s = aword) then
  66.       if not getAt(gHitList, midPt) then
  67.         set bFound to the number of words in midLine
  68.         setAt(gHitList, midPt, 1)
  69.         if bFound > 1 then
  70.           set gSecondGlossWord to word 2 of midLine
  71.         end if
  72.       end if
  73.       set bExit to 1
  74.       next repeat
  75.     end if
  76.     if stPt >= EndPt then
  77.       set bExit to 1
  78.     end if
  79.     if midLine > aword then
  80.       set EndPt to midPt - 1
  81.       next repeat
  82.     end if
  83.     set stPt to midPt + 1
  84.   end repeat
  85.   return bFound
  86. end
  87.  
  88. on resetHit
  89.   global gHitList
  90.   set gHitList to []
  91.   repeat with a = 1 to the number of lines in field "glossary"
  92.     add(gHitList, 0)
  93.   end repeat
  94. end
  95.  
  96. on wordFilter oWord
  97.   set cc to the number of chars in oWord
  98.   set c1 to charToNum(char 1 of oWord)
  99.   set CL to charToNum(char cc of oWord)
  100.   set bC1isAlpha to isAlpha(c1)
  101.   set bCLisAlpha to isAlpha(CL)
  102.   if bC1isAlpha and bCLisAlpha then
  103.     set fWord to oWord
  104.   else
  105.     set fWord to oWord
  106.     repeat while not bC1isAlpha and (cc > 2)
  107.       delete char 1 of fWord
  108.       set cc to cc - 1
  109.       set c1 to charToNum(char 1 of fWord)
  110.       set bC1isAlpha to isAlpha(c1)
  111.     end repeat
  112.     set cc to the number of chars in fWord
  113.     repeat while not bCLisAlpha and (cc > 2)
  114.       delete char cc of fWord
  115.       set cc to cc - 1
  116.       set CL to charToNum(char cc of fWord)
  117.       set bCLisAlpha to isAlpha(CL)
  118.     end repeat
  119.   end if
  120.   return fWord
  121. end
  122.  
  123. on isAlpha C
  124.   return ((C >= 65) and (C <= 90)) or ((C >= 97) and (C <= 122))
  125. end
  126.